package com.example.web;

import com.example.model.Ltree;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: ym
 * @create: 2019-08-25
 **/
@Controller
public class ThymeleafController {

    @RequestMapping("/thymeleaf")
    public String adf(ModelMap map){
        map.put("hello","i am thymeleaf");
        return "test";
    }

    @RequestMapping("/tree")
    public String tree(ModelMap map){
        map.put("treeData",getTree());
        return "demo/layuitreetest";
    }

    public static List<Ltree> getTree(){

        List<Ltree> t = new ArrayList<>();
        Ltree tree = new Ltree();
        tree.setId(1);
        tree.setTitle("demo");
        Ltree tree2 = new Ltree();
        tree2.setId(2);

        tree2.setTitle("sdafa");
        Ltree tree3 = new Ltree();
        tree3.setId(3);
        tree3.setpId(2);
        tree3.setTitle("ghjd");
        List<Ltree> cList = new ArrayList<>();
        cList.add(tree3);
        tree2.setChildren(cList);
        t.add(tree);
        t.add(tree2);


        return t;
    }
}
